package java69.work717_2;

public class Voter {
    private  static  int count = 0;//创建一个对象，count会+1
    private  static int num = 100;//最多创建100个对象

    private Voter(){
        count++;
    }
    private Voter(int count,int num){
        count++;
    }

    public  static  Voter creatNewVoter(){
        if (count<num){
            return new Voter();
        }else {
            return  null;
        }
    }

    public static int getCount() {
        return count;
    }

    public static void setCount(int count) {
        Voter.count = count;
    }

    public static int getNum() {
        return num;
    }

    public static void setNum(int num) {
        Voter.num = num;
    }

    public static void main(String[] args) {
        while (true){
            Voter voter = Voter.creatNewVoter();
            if (voter == null){
                System.out.println("对不起，已经投了"+Voter.getNum()+"张票");
                break;
            }else {
                System.out.println("投了第"+Voter.getCount()+"张票");
            }
        }
    }
}
